var Withdraw = require('../../domain/withdraw');
var logger = require('pomelo-logger').getLogger(__filename);
var utils = require('../../util/utils');

module.exports = {
    insert: function (withdraw, cb) {
        withdraw.save(function (err, res) {
            if (!!err) {
                logger.error("err: ", err);
                return;
            }
            utils.invokeCallback(cb);
        });
    },
    pageQuery: function (page, cb) {
        var uid = page.uid;
        var pageNum = page.pageNum;
        var pageSize = page.pageSize;
        var currentPage = (pageNum - 1) * pageSize;
        Withdraw.find({uid: uid}).skip(currentPage).limit(pageSize).sort({gmt_create: -1}).select('wid money status gmt_create').exec(cb);
    },
    logQuery: function (uid, money, cb) {
        Withdraw.countDocuments().where({uid: uid, super_status: 2, status: 2, money: money}).exec(cb);
    },
    checkSecondWithdraw: function (uid, money, cb) {
        Withdraw.countDocuments().where({uid: uid, super_status: 1, money: money}).exec(cb);
    }
}